Add TCP fallback and automatic reconnection with exponential backoff#36
Merged
infinityabundance merged 4 commits intomainfrom Feb 13, 2026
Merged
Conversation
…straction Co-authored-by: infinityabundance <255699974+infinityabundance@users.noreply.github.com>
Co-authored-by: infinityabundance <255699974+infinityabundance@users.noreply.github.com>
…math for backoff, iterate backwards when removing peers Co-authored-by: infinityabundance <255699974+infinityabundance@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add TCP fallback and connection recovery logic
Add TCP fallback and automatic reconnection with exponential backoff
Feb 13, 2026
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements multi-layer network resilience: UDP remains primary transport, TCP fallback activates when UDP fails (firewalls, NAT issues), automatic reconnection with exponential backoff handles transient failures.
Details
What changed?
Transport Abstraction Layer
rootstream_net_send_encrypted()dispatches to UDP or TCP based onpeer->transportrootstream_net_recv()polls both UDP socket and active TCP peersrootstream_net_handshake()tries UDP first, falls back to TCP on failureTCP Fallback Transport (
src/network_tcp.c)Automatic Reconnection (
src/network_reconnect.c)Connection Monitoring (
src/service.c)check_peer_health()in main loopData Structures
Rationale
Problem: UDP blocked by firewalls/NAT = streaming fails immediately. Network drops = no recovery.
Solution: Multi-tier fallback aligns with RootStream's goal of reliability without complexity:
Typical UDP latency: 1-5ms. TCP adds 20-50ms overhead but maintains connectivity through restrictive networks.
Testing
make)gcc -con new modules)check_peer_health()fmin())Test Scenarios to Validate:
Notes
Original prompt
PHASE 4: Robust Networking & Connection Resilience
Current State
src/network.c- Core UDP protocol, encryption, handshake (fully implemented)src/network_stub.c- Stub when NO_CRYPTO buildProblem
Currently in network code:
On networks with:
Streaming fails immediately with no recovery path.
Solution: Multi-Layer Network Resilience
Tier 1: Direct UDP (Primary)
src/network.c(already exists)Tier 2: TCP Fallback (New)
src/network_tcp.c(NEW)Tier 3: Connection Recovery (New)
src/network_reconnect.c(NEW)Implementation
File 1:
src/network_tcp.c- TCP Fallback Transport